home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 11683 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.9 KB

  1. Path: gambier.ugrad.cs.ubc.ca!not-for-mail
  2. From: c2a192@ugrad.cs.ubc.ca (Kazimir Kylheku)
  3. Newsgroups: comp.lang.ada,comp.lang.c,comp.lang.c++
  4. Subject: Re: C/C++ knocks the crap out of Ada
  5. Date: 15 Mar 1996 09:48:49 -0800
  6. Organization: Computer Science, University of B.C., Vancouver, B.C., Canada
  7. Message-ID: <4icai1INN608@gambier.ugrad.cs.ubc.ca>
  8. References: <JSA.96Feb16135027@organon.com> <4hm6lo$eln@fred.netinfo.com.au> <4hml8s$a1q@solutions.solon.com> <DoBIoL.1JC@world.std.com>
  9. NNTP-Posting-Host: gambier.ugrad.cs.ubc.ca
  10.  
  11. In article <DoBIoL.1JC@world.std.com>,
  12. Robert A Duff <bobduff@world.std.com> wrote:
  13.  >In article <4hml8s$a1q@solutions.solon.com>,
  14.  >Peter Seebach <seebs@solutions.solon.com> wrote:
  15.  >>Certainly.  A C implementation is free to be an interpreter that emulates
  16.  >>every bit of every value and checks for arbitrary programming errors.
  17.  >>
  18.  >>There is no restriction that an implementation may not offer range checking,
  19.  >>and many already do have stricter type checking than the standard requires.
  20.  >
  21.  >But C doesn't have any syntax for defining the range of an int, except:
  22.  >
  23.  >    int x; /* x is always between 1 and 10 */
  24.  >
  25.  >So how can a C implementation check this range, without extending the
  26.  >syntax of the language?  There are many other examples.
  27.  
  28. Quite frankly, you can't do it. If the integer is not used as any sort of array
  29. index, you don't know what the range is. Here are some alternatives:
  30.  
  31. 1.    Use an enumerated type. Drawback: it's not an arithmetic type.
  32.     Incrementing an enumerated variable, for instance, is a no no.
  33.     An expression involving an enumerated type promotes it to an
  34.     int, and can't be assigned back to the enumerated type.
  35.  
  36. 2.    assert() macros. This is ugly, and places the burden on the programmer.
  37.     It does work, however, and _is_ standardized.
  38.  
  39. Specifying ranges for integers is something that I dearly miss about Modula 2.
  40. (But that's about it...) It really is a significant feature.
  41. -- 
  42.  
  43.